package com.msb.c03;

/**
 * @author: xw
 * @create: 2022/9/22 11:37
 * @description:
 */
public class SynchronizedTest02 implements Runnable{
    private /*volatile*/ int count = 100;


    public synchronized void run1() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count--;
        System.out.println(Thread.currentThread().getName() + " count = " + count);
    }

    @Override
    public  void run() {
        synchronized (this){
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            count--;
            System.out.println(Thread.currentThread().getName() + " count = " + count);
        }
    }

    public static void main(String[] args) {
        SynchronizedTest02 t = new SynchronizedTest02();
        for(int i=0; i<100; i++) {
            new Thread(t, "THREAD" + i).start();
        }
    }
}
